package com.facebook.presto.tdengine;

import com.facebook.presto.spi.ConnectorHandleResolver;
import com.facebook.presto.spi.connector.Connector;
import com.facebook.presto.spi.connector.ConnectorContext;
import com.facebook.presto.spi.connector.ConnectorFactory;

import java.util.Map;

public class TdEngineConnectorFactory implements ConnectorFactory {
    private static final String TDENGINE_CONNECTOR = "tdengine";

    @Override
    public String getName() {
        return TDENGINE_CONNECTOR;
    }

    @Override
    public ConnectorHandleResolver getHandleResolver() {
        return new TdEngineHandleResolver();
    }

    //该url就是tdengine.properties配置文件中的url
    @Override
    public Connector create(String catalogName, Map<String, String> config, ConnectorContext context) {
        String url = config.get("url");
        TdEngineConnector connector = null;
        try {
            connector = new TdEngineConnector(url, catalogName);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
        return connector;
    }
}
